package com.hgy.commonsale.service.impl;

import java.util.List;

import org.geln.web.hibernate.BaseHibernateService;
import org.geln.web.status.Status;
import com.hgy.commonsale.service.CustomerUserManagerService;
import com.hgy.commonsale.user.domain.CustomerUser;

public class CustomerUserManagerServiceImpl extends BaseHibernateService
		implements CustomerUserManagerService {

	public Object saveOrUpdate(CustomerUser user) {
		return null;
	}
	
	public Object saveObject(CustomerUser user){
		if(validateExists(user)){
			return null;
		}else{
			getHibernateTemplate().save(user);
			return Status.SUCCESS;
		}
	}
	
	public Object updateObject(CustomerUser user){
		return null;
	}
	
	public Status deleteObjectByUserName(String userName){
		CustomerUser customerUser=getUserByUserName(userName);
		if(customerUser!=null){
			getHibernateTemplate().delete(customerUser);
			return Status.SUCCESS;
		}else{
			return Status.FAILED_FOR_NULL;
		}
		
	}
	
	
	public CustomerUser getUserByID(String ID){
		return null;
	}
	
	/**
	 * ͨ���û��������Ӧʵ��
	 * @param userName
	 * @return
	 */
	public CustomerUser getUserByUserName(String userName){
		
		String queryString="from CustomerUser customerUser where customerUser.userNo=?";
		List<CustomerUser> lstCustomer=getHibernateTemplate().find(queryString, new String[]{userName});
		
		if(lstCustomer.size()>0){
			return  lstCustomer.get(0);
		}else{
			return null;
		}
		
	}
	
	/**
	 * ��֤Customer�Ƿ��Ѵ���
	 * 
	 * @param user
	 * @return true:���ڸ��û�
	 *        false:������
	 */
	protected boolean validateExists(CustomerUser user){
		boolean flag=false;
		//����ͬ�û����û�
		if(getUserByUserName(user.getUserNo())!=null){
			flag=true;
		}
		
		return flag;
	}
	
	
	public List<CustomerUser> getCustomerUserList(){
		String queryString="from CustomerUser";
		List<CustomerUser> lstCustomer=getHibernateTemplate().find(queryString);
		
		if(lstCustomer.size()>0){
			return lstCustomer;
		}else{
			return null;
		}
	}
}